nanopyx.liquid.__opencl__
1import os 2import warnings 3 4os.environ["PYOPENCL_COMPILER_OUTPUT"] = "1" 5 6try: 7 import pyopencl as cl 8 import pyopencl.array as cl_array 9 10 devices = [] 11 for platform in cl.get_platforms(): 12 if 'Microsoft' in platform.vendor: 13 continue 14 for dev in platform.get_devices(): 15 # check if the device is a GPU 16 if "GPU" not in cl.device_type.to_string(dev.type): 17 continue 18 if 'cl_khr_fp64' in dev.extensions.strip().split(' '): 19 cl_dp = True 20 else: 21 cl_dp = False 22 23 devices.append({'device':dev, 'DP':cl_dp}) 24 25 26except (ImportError, OSError, Exception): 27 cl = None 28 cl_array = None 29 devices = None 30 31 32def print_opencl_info(): 33 """ 34 Prints information about the OpenCL devices on the system 35 """ 36 # REF: https://github.com/benshope/PyOpenCL-Tutorial 37 38 msg = "\n" + "=" * 60 + "\nOpenCL Platforms and Devices \n" 39 # Print each platform on this computer 40 for platform in cl.get_platforms(): 41 msg += "=" * 60 + "\n" 42 msg += "Platform - Name: " + platform.name + "\n" 43 msg += "Platform - Vendor: " + platform.vendor + "\n" 44 msg += "Platform - Version: " + platform.version + "\n" 45 msg += "Platform - Profile: " + platform.profile + "\n" 46 # Print each device per-platform 47 for device in platform.get_devices(): 48 msg += "\t" + "-" * 56 + "\n" 49 msg += "\tDevice - Name: " + device.name + "\n" 50 msg += "\tDevice - Type: " + cl.device_type.to_string(device.type) + "\n" 51 msg += f"\tDevice - Max Clock Speed: {device.max_clock_frequency} Mhz" + "\n" 52 53 msg += f"\tDevice - Compute Units: {device.max_compute_units}" + "\n" 54 msg += f"\tDevice - Local Memory: {device.local_mem_size / 1024.0:.0f} KB" + "\n" 55 msg += f"\tDevice - Constant Memory: {device.max_constant_buffer_size / 1024.0:.0f} KB" + "\n" 56 msg += f"\tDevice - Global Memory: {device.global_mem_size / 1073741824.0:.0f} GB" + "\n" 57 msg += f"\tDevice - Max Buffer/Image Size: {device.max_mem_alloc_size / 1048576.0:.0f} MB" + "\n" 58 msg += f"\tDevice - Max Work Group Size: {device.max_work_group_size:.0f}" + "\n" 59 60 return msg 61 62 63def opencl_works(): 64 """ 65 Checks if the system has OpenCL compatibility 66 :return: True if the system has OpenCL compatibility, False otherwise 67 """ 68 disabled = os.environ.get("NANOPYX_DISABLE_OPENCL", "0") == "1" 69 enabled = os.environ.get("NANOPYX_ENABLE_OPENCL", "1") == "1" 70 71 if disabled or not enabled: 72 warnings.warn( 73 "OpenCL is disabled. To enable it, set the environment variable NANOPYX_ENABLE_OPENCL=1" 74 ) 75 return False 76 77 elif enabled: 78 if cl is None: 79 warnings.warn("tap... tap... tap... COMPUTER SAYS NO (OpenCL)!") 80 os.environ["NANOPYX_DISABLE_OPENCL"] = "1" 81 return False 82 83 return True
def
print_opencl_info():
33def print_opencl_info(): 34 """ 35 Prints information about the OpenCL devices on the system 36 """ 37 # REF: https://github.com/benshope/PyOpenCL-Tutorial 38 39 msg = "\n" + "=" * 60 + "\nOpenCL Platforms and Devices \n" 40 # Print each platform on this computer 41 for platform in cl.get_platforms(): 42 msg += "=" * 60 + "\n" 43 msg += "Platform - Name: " + platform.name + "\n" 44 msg += "Platform - Vendor: " + platform.vendor + "\n" 45 msg += "Platform - Version: " + platform.version + "\n" 46 msg += "Platform - Profile: " + platform.profile + "\n" 47 # Print each device per-platform 48 for device in platform.get_devices(): 49 msg += "\t" + "-" * 56 + "\n" 50 msg += "\tDevice - Name: " + device.name + "\n" 51 msg += "\tDevice - Type: " + cl.device_type.to_string(device.type) + "\n" 52 msg += f"\tDevice - Max Clock Speed: {device.max_clock_frequency} Mhz" + "\n" 53 54 msg += f"\tDevice - Compute Units: {device.max_compute_units}" + "\n" 55 msg += f"\tDevice - Local Memory: {device.local_mem_size / 1024.0:.0f} KB" + "\n" 56 msg += f"\tDevice - Constant Memory: {device.max_constant_buffer_size / 1024.0:.0f} KB" + "\n" 57 msg += f"\tDevice - Global Memory: {device.global_mem_size / 1073741824.0:.0f} GB" + "\n" 58 msg += f"\tDevice - Max Buffer/Image Size: {device.max_mem_alloc_size / 1048576.0:.0f} MB" + "\n" 59 msg += f"\tDevice - Max Work Group Size: {device.max_work_group_size:.0f}" + "\n" 60 61 return msg
Prints information about the OpenCL devices on the system
def
opencl_works():
64def opencl_works(): 65 """ 66 Checks if the system has OpenCL compatibility 67 :return: True if the system has OpenCL compatibility, False otherwise 68 """ 69 disabled = os.environ.get("NANOPYX_DISABLE_OPENCL", "0") == "1" 70 enabled = os.environ.get("NANOPYX_ENABLE_OPENCL", "1") == "1" 71 72 if disabled or not enabled: 73 warnings.warn( 74 "OpenCL is disabled. To enable it, set the environment variable NANOPYX_ENABLE_OPENCL=1" 75 ) 76 return False 77 78 elif enabled: 79 if cl is None: 80 warnings.warn("tap... tap... tap... COMPUTER SAYS NO (OpenCL)!") 81 os.environ["NANOPYX_DISABLE_OPENCL"] = "1" 82 return False 83 84 return True
Checks if the system has OpenCL compatibility
Returns
True if the system has OpenCL compatibility, False otherwise